home *** CD-ROM | disk | FTP | other *** search
- :
- # @(#) tsum 25.2 92/06/19
- #
- # Copyright (C) 1988-1992 The Santa Cruz Operation, Inc.,
- # This Module contains Proprietary Information of
- # The Santa Cruz Operation, and should be treated as Confidential.
- #
- # tsum: used for summing bundled tapes, should work on xenix or unix
- # this program is internal SCO bundle tape summing technology
- # WARNING: DO NOT use for summing standard tapes, these
- # should still be summed using: dd if=dev | sum -r
-
- # mikeeb 6/12/92
- # 322 based system had problems with SCSI tape
- # marks so we will assume that we won't have
- # products with more than 50 tape marks, to catch errors
- #
- # tonyj 18 Jun 1992
- # Add the -R option to specify how many records to read from the tape.
- # If the -R option is not used, reaching $COUNTLIMIT (50) records is regarded
- # as an error, probably caused by overrunning the end of the tape.
-
- # These are the main types of tape devices
- # Move which ever one you want as the default into
- # the last position
- TAPEDEVICE=/dev/nrcdt0 # Standard CD device
- TAPEDEVICE=/dev/nrStp0 # Standard SCSI Tape device
- TAPEDEVICE=/dev/nrct0 # Standard tape device
-
- COUNTLIMIT=50 # Maximum number of records to read
- # from the tape. If the user has not
- # specified a value, regard reaching
- # COUNTLIMIT as an error, probably caused
- # by missing the end-of-tape marker.
- RFLAG=NO # If 'YES', user has specified a countlimit
- # with the -R option; do not issue
- # an error message when the limit
- # is reached.
- BSFACTOR=5k # Blocking factor
- TMPTSUM=/tmp/tsum$$
- TMPCOUNT=/tmp/count$$
- TMPFILE=/tmp/tsumtmp$$
- ERRORFILE=/tmp/error$$
-
- tapereset () {
- RESETDEV=$1
- echo "Reseting Device $RESETDEV...\c"
- sleep 1
- case $RESETDEV in
- *ct0)
- TAPEARG="-c"
- RESETCNTRLDEV=/dev/xct0
- ;;
- *Stp0) TAPEARG="-s"
- RESETCNTRLDEV=/dev/xStp0
- ;;
- *Stp1) TAPEARG="-s"
- RESETCNTRLDEV=/dev/xStp1
- ;;
- *cdt0) TAPEARG="-s"
- RESETCNTRLDEV=/dev/xcdt0
- ;;
- *) error "Unable to determine cntrl device"
- return 1
- ;;
- esac
- case `uname -r` in
- 2.*) echo "rewinding..."
- tape rewind $RESETCNTRLDEV || return 1
- ;;
- *) echo "reseting...\c"
- tape $TAPEARG reset $RESETCNTRLDEV || return 1
- sleep 1
- echo "rewinding..."
- tape $TAPEARG rewind $RESETCNTRLDEV || return 1
- sleep 1
- ;;
- esac
- sleep 1
- return 0
- }
-
- tsum() {
- # parse args, check needed vars
- [ $# = 3 ] || {
- echo "ERROR: incorrect arg count to $0"
- usage
- exit 1
- }
- [ "$COUNTLIMIT" ] || {
- echo "ERROR: variable COUNTLIMIT must be set"
- exit 1
- }
- TSUMDEVICE=$1
- TSUMFILE=$2
- TSUMCOUNTFILE=$3
- RETURNCODE=0
- COUNT=0
-
- # sum tape
- [ -f $ERRORFILE ] && rm -f $ERRORFILE
-
- while dd if=$TSUMDEVICE bs=$BSFACTOR 2> $TMPFILE
- do
- # check input/output records
- inrec=`head -1 $TMPFILE | awk '{print $1}'`
- outrec=`tail -1 $TMPFILE | awk '{print $1}'`
- [ "$inrec" = "0+0" -a "$outrec" = "0+0" ] && {
- echo "1" >$ERRORFILE 2>&1
- break
- }
-
- # check count of records
- COUNT=`expr $COUNT + 1`
- echo $COUNT > $TSUMCOUNTFILE 2>&1
- expr $COUNT = $COUNTLIMIT > /dev/null 2>&1 && {
- if [ "$RFLAG" = "NO" ] ; then # Overrun error...
- echo "2" >$ERRORFILE 2>&1
- fi
- break
- }
- done | sum -r | sed 's/^\(.....\)/\1 /' > $TSUMFILE
- rm -f $TMPFILE
- [ -s $ERRORFILE ] && { # Error output was produced.
- case `cat $ERRORFILE` in
- 1)
- echo "WARNING: multiple sequential blank records"
- echo "Assuming the end of the tape."
- echo "This may be tied to 322-324 SCSI"
- echo "tape driver problems."
- echo "The tsum may be inaccurate."
- return 1
- ;;
- 2)
- echo "ERROR: problems have been encountered"
- echo "whith the $TAPEDEVICE device driver."
- echo "more than $COUNTLIMIT tape marks found"
- return 2
- ;;
- esac
- }
- return 0
- }
-
- displaytsum() {
- TSUMFILE=$1
- TCOUNTFILE=$2
-
- TSUM=`cat $TSUMFILE | awk '{print $1}'`
- TVOLUME=`cat $TSUMFILE | awk '{print $2}'`
- TCOUNT=`cat $TCOUNTFILE`
- echo "tsum (tape sum) = $TSUM volume (512 byte blocks) = $TVOLUME tape records = $TCOUNT"
- return 0
- }
-
- usage() {
- echo "usage: tsum [-u] [-R count] [device path]"
- echo " -R <count> Read only the specified number of records"
- echo " -u Display this usage message"
- echo " "
- echo " current valid device paths:"
- echo " /dev/nrct0 Standard Tape"
- echo " /dev/nrStp0 SCSI Tape 0"
- echo " /dev/nrStp1 SCSI Tape 1"
- echo " /dev/nrcdt0 CD Rom"
- echo " /dev/nurStp0 8mm SCSI Tape 0"
- echo " /dev/nurStp1 8mm SCSI Tape 1"
- echo " "
- }
-
- validatedevice() {
- DEVICE=`basename $1`
- case $DEVICE in
- nrct0 | nrStp0 | nrStp1 | nurStp0 | nurStp1 | nrcdt0) return 0 ;;
- *) return 1 ;;
- esac
- }
-
- # Print an error message
- error() {
- echo "\nError: $*" >&2
- return $FAIL
- }
-
-
- # MAIN
- # parse args
-
- while [ "$#" != 0 ]
- do
- case $1 in
- -R) RFLAG=YES
- COUNTLIMIT=`expr "0$2" : '\([0-9]*\)'` #Ensure it's numeric.
- if [ -z "$COUNTLIMIT" ] ; then
- error "bad record count with -R option: $2"
- exit $FAIL
- elif [ "$COUNTLIMIT" -le 0 ] ; then
- error "bad record count with -R option: $2"
- exit $FAIL
- fi
- shift ; shift ;;
- -u|-\?) usage ; exit $FAIL ;;
- *) if [ "$#" = 1 ] ; then
- TAPEDEVICE=$1
- else
- error "incorrect arguments: $*"
- usage ; exit $FAIL
- fi
- shift ;;
- esac
- done
-
- [ -r "$TAPEDEVICE" ] || {
- echo "ERROR: tape device $TAPEDEVICE does not exist"
- usage
- exit 1
- }
-
- validatedevice $TAPEDEVICE || {
- echo "ERROR: tape device $TAPEDEVICE is not valid"
- echo "Tape device must be of type no-rewind"
- echo " "
- usage
- echo "Do you want to attempt summing anyway ? (y/n)\c"
- read a
- [ "$a" = "y" ] || {
- exit 1
- }
- }
-
- tapereset $TAPEDEVICE || {
- echo "Error: unable to access device"
- exit 1
- }
-
- echo "Summing bundle tape device $TAPEDEVICE..."
- tsum $TAPEDEVICE $TMPTSUM $TMPCOUNT || exit 1
- displaytsum $TMPTSUM $TMPCOUNT
- rm -f $TMPSUM $TMPCOUNT
-
- tapereset $TAPEDEVICE || {
- echo "Error: unable to access device"
- exit 1
- }
-
- exit 0
-